package com.smh.a03exerciseDemo1;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Test5 {
    public static void main(String[] args) throws IOException {

        FileReader fr = new FileReader("day26-code\\file\\d.txt");

        FileWriter fw = new FileWriter("day26-code\\file\\e.txt");

        char[] chars = new char[1024 * 1024];
        int len;
        StringBuilder sb = new StringBuilder();
        while ((len = fr.read(chars)) != -1) {
            sb.append(chars, 0, len);
//            for (char aChar : chars) {
//                sb.append(aChar);
//            }
        }

        List<Integer> collect = Arrays.stream(sb.toString().split("-"))
                .map(new Function<String, Integer>() {
                    @Override
                    public Integer apply(String s) {
                        return Integer.parseInt(s);
                    }
                })
                .sorted()
                .collect(Collectors.toList());

        //collect.sort((o1, o2) -> o1-o2);

        for (int i = 0; i < collect.size(); i++) {
            if (i == collect.size() - 1) {
                fw.write(collect.get(i) + "");
            } else {
                fw.write(collect.get(i) + "-");
            }
        }

        fw.close();
        fr.close();


    }
}
